from peewee import *
from datetime import datetime
from .base import BaseModel, User, Item

class Address(BaseModel):
    id: int = AutoField(primary_key=True)
    user_id: int = IntegerField(default=0)
    consignee: str = CharField(default='')
    mobile: str = CharField(default='')
    dist_id: int = IntegerField(default=0)
    detail: str = CharField(default='')
    is_default: int = IntegerField(default=0)
    class Meta:
        table_name = 'user_address'

class Favorite(BaseModel):
    id: int = AutoField(primary_key=True)
    name: str = CharField(default='')
    thumb: str = CharField(default='')
    price: int = IntegerField(default=0)
    user_id: int = ForeignKeyField(User, to_field='id', backref='favos', default=0)
    item_id: int = ForeignKeyField(Item, to_field='id', backref='favos', default=0)
    create_at: int = IntegerField(default=datetime.now().timestamp())  # 创建时间
    class Meta:
        table_name = 'user_favorite'

class Focus(BaseModel):
    id: int = AutoField(primary_key=True)
    name: str = CharField(default='')
    thumb: str = CharField(default='')
    user_id: int = IntegerField(default=0)
    item_id: int = IntegerField(default=0)
    create_at: int = IntegerField(default=datetime.now().timestamp())  # 创建时间
    class Meta:
        table_name = 'user_focus'

class History(BaseModel):
    id: int = AutoField(primary_key=True)
    name: str = CharField(default='')
    thumb: str = CharField(default='')
    price: int = IntegerField(default=0)
    user_id: int = IntegerField(default=0)
    item_id: int = IntegerField(default=0)
    create_at: int = IntegerField(default=datetime.now().timestamp())  # 创建时间
    class Meta:
        table_name = 'user_history'
